package fr.cnam.ratpProject.client.activities.itinarySearch;

import java.util.ArrayList;

import com.google.gwt.core.shared.GWT;
import com.google.gwt.event.shared.EventBus;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.AcceptsOneWidget;
import com.google.gwt.user.client.ui.IsWidget;

import fr.cnam.ratpProject.client.services.ReseauRatpService;
import fr.cnam.ratpProject.client.services.ReseauRatpServiceAsync;
import fr.cnam.ratpProject.client.utils.GlueProvider;
import fr.cnam.ratpProject.client.utils.RatpActivity;
import fr.cnam.ratpProject.sharedDatas.Station;

public class ItinarySearch extends RatpActivity{

	
	
	public interface ItinarySearchView extends IsWidget {
		public void buildUi();

		void setSuggestStations(ArrayList<Station> result);
	}
	
	private ReseauRatpServiceAsync ratpService = GWT.create(ReseauRatpService.class);

	private ItinarySearchView view;
	
	@Override
	public void start(AcceptsOneWidget panel, EventBus eventBus) {
		
		ratpService.getAllStations(new AsyncCallback<ArrayList<Station>>() {
					
		
					@Override
					public void onSuccess(ArrayList<Station> result) {
						view.setSuggestStations(result);
						view.buildUi();
					}
					
					@Override
					public void onFailure(Throwable caught) {
						// TODO Auto-generated method stub
						
					}
				});
		
		view = GlueProvider.INSTANCE.getClientFactory().getItinarySearchView();
		this.attachView(panel, view);
		view.buildUi();
	}

}
